<?php

namespace App\Kuafu\Customer\Validate;

use App\Kuafu\Customer\Enum\CustomerCodeEnum;
use App\Kuafu\Customer\Model\CustomerModel;
use Illuminate\Http\Request;
use App\Kuafu\Base\Validate\BaseValidate;

class CustomerValidate extends BaseValidate
{
    public static function getCustomerById($data)
    {
        $rules    = [
            'id' => 'required|integer|min:0',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    public static function addCustomer($data)
    {
        $rules    = [
            'mobile' => [
                'required',
                function ($attribute, $value, $fail) use ($data) {
                    if (CustomerModel::query()->where('mobile', '=', $data['mobile'])->first()) {
                        $fail("该手机号已注册!");
                    }
                }
            ]
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    public static function setCustomer($userId)
    {
        $rules    = [
            'userId' => [
                'required',
                'integer',
                function ($attribute, $value, $fail) use ($userId) {
                    if (!CustomerModel::query()->where('id', '=', $userId)) {
                        $fail('用户不存在');
                    }
                }
            ],
        ];
        $messages = [];

        return self::validateCheck(['userId'=>$userId], $rules, $messages);
    }
}
